<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 600px;
            margin: 100px auto;
        }

        .message {
            display: inline-block;
            font-size: 12px;
            color: #999;
            background: url(images/mess.png) no-repeat left center;
            padding-left: 20px;
        }

        .wrong {
            color: red;
            background-image: url(images/wrong.png);
        }

        .right {
            color: green;
            background-image: url(images/right.png);
        }
    </style>
</head>
<body>
    <div class="register">
        <input type="password" class="ipt">
        <p class="message">请输入6~16位密码</p>
    </div>
    <script>
          /* 
            失去焦点，如果密码的长度小于3 ，大于6则提示异常，且更改p标签的类样式
        */
        var input = document.querySelector('.ipt');
        var p = document.querySelector('p');
        input.style.width = '800px';
        input.style.height = '200px';
        input.style.fontSize = '180px';

        // 失去焦点
        input.onblur = function () {
            // console.log('1111');
            // 判断密码的长度
            var psd = input.value;
            if (psd.length < 3 || psd.length > 6) {
                p.innerHTML = "密码长度不能小于3，也不能大于6";
                // 更改样式
                p.className = 'message wrong';
                console.log('error ');
            } else {
                console.log('ok');
                p.innerHTML = "密码设置成功";
                p.className = 'message right';
            }
        }

 
    </script>
</body>
</html>